package com.smart.upms.sys.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.core.starter.base.BaseController;
import com.smart.core.starter.model.R;
import com.smart.upms.sys.param.SysOauthClientDetailsParam;
import com.smart.upms.sys.param.SysOauthClientDetailsQueryParam;
import com.smart.upms.sys.result.SysOauthClientDetailsResult;
import com.smart.upms.sys.service.ISysOauthClientDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author guxiaobai
 * @since 2018-12-05
 */
@Api(description = "oauth2客户端管理接口")
@RestController
@RequestMapping("/sys/sys-oauth-client-details")
@AllArgsConstructor
public class SysOauthClientDetailsController extends BaseController {

    private final ISysOauthClientDetailsService sysOauthClientDetailsService;


    /**
     * 添加客户端
     *
     * @param param 客户端信息
     * @return R
     */
    @ApiOperation(value = "添加客户端")
    @PostMapping
    public R save(@Validated @RequestBody SysOauthClientDetailsParam param) {
        return R.success(sysOauthClientDetailsService.save(param));
    }

    /**
     * 修改客户端
     *
     * @param param 客户端信息
     * @return R
     */
    @ApiOperation(value = "修改客户端")
    @PutMapping
    public R update(@Validated @RequestBody SysOauthClientDetailsParam param) {
        return R.success(sysOauthClientDetailsService.update(param));
    }

    /**
     * 通过id删除
     *
     * @param clientId 客户端id
     * @return R
     */
    @ApiOperation(value = "通过id删除")
    @DeleteMapping("/{clientId}")
    public R delete(@PathVariable String clientId) {
        return R.success(sysOauthClientDetailsService.delete(clientId));
    }


    /**
     * 通过id查询
     *
     * @param clientId 客户端id
     * @return R
     */
    @ApiOperation(value = "通过id查询")
    @GetMapping("/{clientId}")
    public R<SysOauthClientDetailsResult> getById(@PathVariable String clientId) {
        return R.success(sysOauthClientDetailsService.get(clientId));
    }


    /**
     * 分页查询
     *
     * @param param 查询参数
     * @return
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    public R<Page<SysOauthClientDetailsResult>> getSysOauthClientDetailsPage(SysOauthClientDetailsQueryParam param) {
        Page<SysOauthClientDetailsResult> page = getPage(param);
        return R.success(sysOauthClientDetailsService.listPage(page, param));
    }





}
